﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YourWallet;

namespace yourwallet_test
{
    [TestClass]
    public class Transaction_tests
    {
        [TestMethod]
        public void Transaction_getters()
        {
            DateTime date = new DateTime(2013, 7, 14);
            double amount = 1000;
            string category = "category";
            string note = "note";

            Transaction income = new Transaction("account", amount, category, date, note, TransactionType.Income);

            Assert.AreEqual(category, income.GetCategory());
            Assert.AreEqual(amount, income.GetAmount());
            Assert.AreEqual(note, income.GetNote());
            Assert.AreEqual(date, income.GetDate());
            Assert.AreEqual(true, income.IsIncome());
            Assert.AreEqual("Income", income.GetTransactionType().ToString());
        }

        [TestMethod]
        public void Transaction_setters()
        {
            string old_accountName = "account";
            DateTime old_date = new DateTime(2013, 7, 14);
            double old_amount = 1000;
            string old_category = "category";
            string old_note = "note";
            TransactionType old_type = TransactionType.Income;

            string new_accountName = "account_new";
            DateTime new_date = new DateTime(2013, 8, 14);
            double new_amount = 100;
            string new_category = "category_new";
            string new_note = "note_new";
            TransactionType new_type = TransactionType.Expense;

            Transaction income = new Transaction(old_accountName, old_amount, old_category, old_date, old_note, old_type);

            Assert.AreEqual(old_accountName, income.GetAccountName());
            Assert.AreEqual(old_category, income.GetCategory());
            Assert.AreEqual(old_amount, income.GetAmount());
            Assert.AreEqual(old_note, income.GetNote());
            Assert.AreEqual(old_date, income.GetDate());
            Assert.AreEqual(true, income.IsIncome());

            income.SetAccountName(new_accountName);
            income.SetCategory(new_category);
            income.SetAmount(new_amount);
            income.SetNote(new_note);
            income.SetDate(new_date);
            income.SetType(new_type);

            Assert.AreEqual(new_accountName, income.GetAccountName());
            Assert.AreEqual(new_category, income.GetCategory());
            Assert.AreEqual(new_amount, income.GetAmount());
            Assert.AreEqual(new_note, income.GetNote());
            Assert.AreEqual(new_date, income.GetDate());
            Assert.AreEqual(true, income.IsExpense());
        }

        [TestMethod]
        public void GetNameShouldReturnCategory_whenNoteIsEmpty()
        {
            DateTime date = new DateTime(2013, 7, 14);
            double amount = 1000;
            string category = "category";
            string note = "";

            Transaction income = new Transaction("account", amount, category, date, note, TransactionType.Income);
            Assert.AreEqual(category, income.GetName());
        }

        [TestMethod]
        public void GetNameShouldReturnNote_whenNoteIsNotEmpty()
        {
            DateTime date = new DateTime(2013, 7, 14);
            double amount = 1000;
            string category = "category";
            string note = "note";

            Transaction income = new Transaction("account", amount, category, date, note, TransactionType.Income);
            Assert.AreEqual(note, income.GetName());
        }

        [TestMethod]
        public void IsIncomeShouldReturnFalse_whenTransactionIsExpense()
        {
            DateTime date = new DateTime(2013, 7, 14);
            double amount = 1000;
            string category = "category";
            string note = "note";

            Transaction expense = new Transaction("account", amount, category, date, note, TransactionType.Expense);
            Assert.AreEqual(false, expense.IsIncome());
            Assert.AreEqual(true, expense.IsExpense());
        }

        [TestMethod]
        public void IsExpenseShouldReturnFalse_whenTransactionIsIncome()
        {
            DateTime date = new DateTime(2013, 7, 14);
            double amount = 1000;
            string category = "category";
            string note = "note";

            Transaction income = new Transaction("account", amount, category, date, note, TransactionType.Income);
            Assert.AreEqual(false, income.IsExpense());
            Assert.AreEqual(true, income.IsIncome());
        }
    }
}
